package com.itbour.service.material.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.material.ProdVerInfoDao;
import com.itbour.dto.com.ProdVerInfoDto;
import com.itbour.service.material.ProdVerInfoService;

public class ProdVerInfoServiceImpl implements ProdVerInfoService {
	private ProdVerInfoDao prodVerInfoDao;

	public void addProdVerInfo(ProdVerInfoDto pro) {
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("device", pro.getDevice());
		parm.put("ver", pro.getVer());
		parm.put("url", pro.getUrl());
		parm.put("release", pro.getRelease());
		parm.put("chk_freq", pro.getChk_freq());
		parm.put("valid", 0);
		parm.put("desc", pro.getDesc());
		parm.put("update_by", pro.getUpdate_by());
		prodVerInfoDao.addProdVerInfo(parm);
	}

	public Page pageProdVerInfo(Integer pageNum, Integer pageSize,
			Map<String, Object> parm) {
		/*
		 * pageNum 第几页 pageSize 一页几条数据 skipNum 起始位置Limit 0,10; totalSize 总共多少条数据
		 */
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = prodVerInfoDao.getProdVerInfoCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<ProdVerInfoDto> data = prodVerInfoDao.pageProdVerInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}

	public void updProdVerInfo(ProdVerInfoDto pro) {
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("id", pro.getId());
		parm.put("ver", pro.getVer());
		parm.put("url", pro.getUrl());
		parm.put("release", pro.getRelease());
		parm.put("chk_freq", pro.getChk_freq());
		parm.put("valid", pro.getValid());
		parm.put("desc", pro.getDesc());
		parm.put("update_by", pro.getUpdate_by());
		prodVerInfoDao.updProdVerInfo(parm);
	}

	@Override
	public List<ProdVerInfoDto> getOneProdVerInfo(Map<String, Object> parm) {
		return prodVerInfoDao.getOneProdVerInfo(parm);
	}

	@Override
	public void delProdVerInfo(Map<String, Object> parm) {
		prodVerInfoDao.delProdVerInfo(parm);
	}

	public ProdVerInfoDao getProdVerInfoDao() {
		return prodVerInfoDao;
	}

	public void setProdVerInfoDao(ProdVerInfoDao prodVerInfoDao) {
		this.prodVerInfoDao = prodVerInfoDao;
	}
}
